package cn.mothin.frame.help;

import java.io.File;
import java.io.FileInputStream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

/**
 * 获取模板内容
 * @author 周士宏
 *
 */
@Component("5385783c382a8fbb66bf65b0")
public class TempletContentHelper {
	public static final String TEMPLET_ROOT="/templet/";
	public static final String TEMPLET_FILE_SUFFIX=".txt";
	
	protected final Log log = LogFactory.getLog(getClass());
	
	/**
	 * 获取模板内容
	 * @param name 模板名称
	 * @return
	 */
	@SuppressWarnings("resource")
	public String getContent(String name){
		try {
			File file = new File(this.getClass().getClassLoader()
					.getResource(TEMPLET_ROOT+name+TEMPLET_FILE_SUFFIX).toURI());
			FileInputStream inputStream = new FileInputStream(file);
			int length = inputStream.available();
			byte[] bytes = new byte[length];
			inputStream.read(bytes, 0, length);
			return new String(bytes, "utf-8");
		} catch (Exception e) {
			log.error(e);
		}
		return null;
	}
}
